package C038;

import java.util.Stack;

/**
 * ClassName: C05
 * Package: C038
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/1/30 11:13
 * @Version 1.0
 * @Since 1.0
 */
public class C05 {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(3);
        stack.push(2);
        stack.push(1);
        //System.out.println(bottomOut(stack));
        System.out.println(stack);
        reverse(stack);
        System.out.println(stack);
    }


    // 调用这个方法需要提前判空
    public static int bottomOut(Stack<Integer> stack) {

        Integer pop = stack.pop();
        if (stack.isEmpty()) {
            return pop;
        }
        int res = bottomOut(stack);
        stack.push(pop);
        return res;
    }

    public static void reverse(Stack<Integer> stack) {
        if(stack.isEmpty()) {
            return;
        }

        int num = bottomOut(stack);
        reverse(stack);
        stack.push(num);
    }
}
